package com.sleep.cloudstreamdemo.controller;

import cn.hutool.core.util.IdUtil;
import com.sleep.cloudstreamdemo.domian.DemoMessage;
import lombok.AllArgsConstructor;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName DemoController
 * @Description TODO
 * @Author 郭敖
 * @Date 2024年04月18日 10:10
 * @Version 1.0
 */
@RestController
@RequestMapping("/demo")
@AllArgsConstructor
public class DemoController {
    private StreamBridge streamBridge;

    @PostMapping("/sendMessage")
    public String sendMessage(@RequestBody DemoMessage message){
        message.setMessageId(IdUtil.getSnowflakeNextId());
        streamBridge.send("demo-out-0",message);
        return "success";
    }
}
